<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('表格传值给父页面')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "transport/isoUnit";
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var unitType = [[${unitType}]];

    $(function() {
        // unitType="+unitType
        console.info(unitType)
        var options = {
            url: prefix + "/list?unitType="+unitType,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            columns: [{
                radio: true
            },
                {
                    title: "序号",
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field: 'unitCode',
                    title: '运输单位类型',
                    sortable: true
                },
                {
                    field: 'description',
                    title: '描述',
                    sortable: true
                },
                {
                    field: 'presentFactor',
                    title: '因素',
                    sortable: true
                },
                {
                    field: 'baseUnit',
                    title: '基本单元',
                    sortable: true
                },
                {
                    field: 'unitType',
                    title: '类型',
                    sortable: true
                }
            ]
        };
        $.table.init(options);
    });

    /* 添加用户-选择用户-提交 */
    function submitHandler(index, layero) {
        // var table= layero.find('iframe')[0];
        // var rows = $.table.selectFirstColumns();
        var row=$("#bootstrap-table").bootstrapTable('getSelections')[0];
        console.info(row.unitCode)
        // var rows = $.table.selectFirstColumns();
        // if (rows.length == 0) {
        //     $.modal.alertWarning("请至少选择一条记录");
        //     return;
        // }
        // parent.$('#weight').val(rows.join());
        $.modal.close();
        // 父页面的方法
        // parent.selectUsers();
        // 父页面的变量
        if(unitType=="Weight"){
            parent.$('#weight').val(row.unitCode);
        }else if(unitType=="Volume"){
            parent.$('#volume').val(row.unitCode);
        }else if(unitType == "NOTUSED"){
            parent.$('#nOTUSED').val(row.unitCode);
        }

    }
</script>
</body>
</html>